<template>
  <el-main style="width:100%">
    <el-table
      v-loading="loading"
      border
      :data="tableData"
    >
      <el-table-column
        label="分发编号"
        align="center"
        prop="fbillcode"
        width="180"
      />
      <el-table-column label="单位名称" prop="fcorporationname" />
      <el-table-column
        label="开始时间"
        align="center"
        :formatter="formatDate"
        prop="fcreatetime"
        width="180"
      />
      <el-table-column
        label="办结时间"
        align="center"
        :formatter="formatDate"
        prop="ffinishedtime"
        width="180"
      />
      <el-table-column
        label="缴费方式"
        align="center"
        prop="fpaymentmethods"
        width="180"
      />
      <el-table-column
        label="发图单返回情况"
        align="center"
        :formatter="formatterStatus"
        prop="freturnsituation"
        width="180"
      />
      <el-table-column
        label="资料是否齐全"
        align="center"
        prop="fiscompletematerial"
        width="180"
      />
      <el-table-column
        label="分发状态"
        align="center"
        :formatter="formatterIssuesStatus"
        prop="fissuedstate"
        width="180"
      />
    </el-table>

    <pagination style="background-color: transparent;"
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getReportData"
    />
  </el-main>
</template>

<script>
import { get4DReport,getTotalReportMainList,getTotalReportDetailList} from "@/api/report/basic";
import { listMateri} from "@/api/materi/materi";


export default {
  name: "table3_0",
  data() {
    return {
      tableData: [],
      expMainTable: [],
      expDetailTable: [],
      loading: false,
      total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        fcorporationname: undefined,
        keyword: undefined,
        beginTime: undefined,
        endTime: undefined,
      },
    };
  },
  mounted: function () {
   // this.getSpanArr(this.tableData0_0);  //暂时不需要合并行
    let date = new Date(); 
    this.$emit("reportSearch","");
  },
  methods:{
    getReportData(queryParam) {
      this.loading = true;
      let that = this;
      if((queryParam)&&(queryParam.beginTime)){
         this.queryParams.beginTime = queryParam.beginTime;
         this.queryParams.endTime = queryParam.endTime;
         this.loading = true;
         listMateri(that.queryParams).then((response) => {
             that.tableData = response.rows;
             that.total = response.total;
             that.loading = false;
           }
         );
      }else{
         listMateri(that.queryParams).then(response => {
             that.tableData = response.rows;
             that.total = response.total;
             that.loading = false;
           }
         );
      }
    },
    formatDate(row, column) {
      // 获取单元格数据
      let data = row[column.property];
      if (data == null) {
        return null;
      }
      let dt = new Date(data);
      return dt.getFullYear() + "-" + (dt.getMonth() + 1) + "-" + dt.getDate();
    },
    //发图单返回状态
    formatterStatus(row, column) {
      switch (row.freturnsituation) {
        case "staReturned":
          return "已返回";
          break;
        case "staUnReturned":
          return "未返回";
          break;
        default:
          return "未知";
      }
    },
    //分发状态
    formatterIssuesStatus(row, column) {
      switch (row.fissuedstate) {
        case "staHandling":
          return "正在进行";
          break;
        case "staHandled":
          return "已分发";
          break;
        default:
          return "未知";
      }
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map(v => filterVal.map(j => v[j]));
    },
    export2Excel(name) {
       getTotalReportMainList(this.queryParams).then(response=>{
         console.log(response.rows);
         this.expMainTable = response.rows;
         
         getTotalReportDetailList(this.queryParams).then(response=>{
           console.log(response.rows);
           this.expDetailTable = response.rows;
           
         
           const tHeader = ["申请单ID","分发编号","发图单位","单位名称","法定代表人","详细地址","邮政编码",
                        "所处县市","单位类型","单位保管保密资料的机构、负责人","所属行业","申请单位组织代码证证号",
                        "客户经办人","身份证号","协议编号","领图人","领图日期","联系电话","提供方式","是否有偿","用途",
                        "是否通过资质审查","通过资质审查时间","外省测绘局审批人","外省测绘局审批日期","使用目的",
                        "项目来源","资料提供时间","办结时间","缴费方式","开始时间","使用期限","成果名称","项目类型"];
           var filterVal = ["fguid","fissueno","fsendmaporg","fcorporationname","flegalperson","faddress","fzipcode",
                            "fcounty","fcorporationtype","fcoandmanager","findustry","forgcreditnum",
                            "fmanagername","fidcardnum","fagreementnum","fclaimperson","fclaimdate","fcontacttel","fsupplyway","fispaid","fuse",
                            "fischeckedqa","fcheckeddate","fprovapprover","fprovapprovedate","fusepurpose",
                            "fprjfrom","fmaterialsupplydate","ffinishedtime","fpaymentmethods","fcreatetime","flifespan","fresultname","fprjtype"];
           var mainSheetName = "申请单";

                            
           const tOrderHeader = ["订单明细ID","申请单ID","资源编号","资源uri","图号","图名","旧图号","数据类型","密级","生产年代",
                            "保密号","数量","提供方式","比例尺","数据格式","单位","数据量","覆盖范围","金额","订单编码",
                            "分发类型","dataId","坐标系","色别","等级","高程基准","分辨率","传感器","景号","省",
                            "市","区","数据现势性","区域名称","备注","加工类型"];
           var OrderFilterVal = ["fguid","fmainguid","fcapitalno","fcapitaluri","fdrawingno","fdrawingname","folddrawingno","fdatatype","fsecretgrade","fproductdate",
                            "fsecretno","fqty","fsupplyway","fmapscale","fdataformat","fdataunit","fdatasize","fcoveragerange","famount","fordercode",
                            "fissuedtype","f_dataid","f_coordinatesystem","fcolortype","fpointgrade","fgaochengjizhun","fresolution","fcmos","fscenenos","fprovince",
                            "fcity","fcounty","fdatacurrent","fareaname","fmemo","fprocesstype"];
           console.log(filterVal)
           // common.export2Excel(name,tHeader,filterVal,this.tableData0_0)
           require.ensure([], () => {
              const { export_json_to_excel } = require("@/views/basic-report/common/Export3_0");
              const list = this.expMainTable;
              const data = this.formatJson(filterVal, list);

              
              const list2 = this.expDetailTable;
              const data2 = this.formatJson(OrderFilterVal, list2);
          
              export_json_to_excel(tHeader, data, name,tOrderHeader,data2,mainSheetName);
           });
         });
       });

    }
  }
};
</script>
<style scoped>
.el-row{
  margin:12px 0;
}
/* .tableX为要显示滚动条的类名 */
/* 显示横向滚动条
.tableX .el-table--scrollable-x .el-table__body-wrapper {
  padding: 0 0 5px 0;
  margin: 0 0 5px 0;
  overflow-x: auto;
}*/
/* 滚动条的滑块样式*/
.tableX .el-table .el-table__body-wrapper::-webkit-scrollbar-thumb {
  background-color: #ccc !important;
  border-radius: 30px !important;
}
/* 去除右侧固定定位阴影多出来的像素
.tableX .el-table__fixed-right{
  height: calc(100% - 27px) !important;
}*/
.el-table__body-wrapper::-webkit-scrollbar{
   height:20px !important;
 }
</style>
